﻿using Web.API.IBLL;
using Web.API.IDAL;
using Web.API.Model;

namespace Web.API.BLL
{
    public class MemberBLL:MemberIBLL
    {
        public MemberBLL(MemberIDAl<MemberModel> dal) 
        {
            Dal = dal;
        }
        public MemberIDAl<MemberModel> Dal { get;}

        public Task<int> AddMember(MemberModel member)
        {
           return Dal.AddAsync(member);
        }

        public MemberModel Fantian(int id)
        {
            return Dal.GetAll().FirstOrDefault(x=>x.Id==id);
        }

        public dynamic GetMember(string? name, int index, int size)
        {
            var list = Dal.GetAll();
            if (!string.IsNullOrEmpty(name))
            {
                list = list.Where(x=>x.Name.Contains(name));
            }
            var c=list.Count();
            var d=list.OrderBy(x=>x.Id).Skip((index-1)*size).Take(size).ToList();
            return new
            {
                count=c,
                data=d
            };
        }
    }
}
